package main

import "fmt"

type IAdder func(int) (int, IAdder)

func adder2(base int) IAdder {
	return func(v int) (i int, iAdder IAdder) {
		return base + v, adder2(base + v)
	}
}

func main() {
	ad2 := adder2(0)
	for i := 0; i < 10; i++ {
		var i2 int
		i2, ad2 = ad2(i)
		fmt.Printf("i=%d  sum= %d \n", i, i2)
	}
}
